﻿<!-- code mirror code http://codemirror.net/ -->
<script type="text/javascript" src="<?php echo base_url("js"); ?>/codemirror/lib/codemirror.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/mode/xml/xml.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/lib/util/javascript-hint.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/mode/javascript/javascript.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/mode/css/css.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/mode/clike/clike.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/mode/php/php.js"></script>
<script src="<?php echo base_url("js"); ?>/codemirror/lib/util/simple-hint.js"></script>
<link rel="stylesheet" href="<?php echo base_url("js"); ?>/codemirror/lib/util/simple-hint.css">
<link rel="stylesheet" href="<?php echo base_url("js"); ?>/codemirror/lib/codemirror.css">

<style>

br
{
	clear:both;
}
label {
	float:left;
}
input, select
{
	float:left;
}
textarea
{
	width:100%;
	height:35%;

}

</style>
<script>

$(function(){

	/* building buttons and attach click events */
	$( "#btnNewsCreateNew" ).button({
		icons: {
			primary: "ui-icon-circle-plus"
		},
		text: true
    });
	$( "#btnNewsBack" ).button({
		icons: {
			primary: "ui-icon-arrowreturnthick-1-w"
		},
		text: true
    });

	editor_short = CodeMirror.fromTextArea(document.getElementById("txtShort"), {
		lineNumbers: true,
		matchBrackets: true,
		mode: "application/x-httpd-php",
		indentUnit: 4,
		indentWithTabs: true,
		enterMode: "keep",
		tabMode: "shift",
		extraKeys: {"Ctrl-Space": function(cm) {CodeMirror.simpleHint(cm, CodeMirror.javascriptHint);}}
	});

	editor_full = CodeMirror.fromTextArea(document.getElementById("txtFull"), {
		lineNumbers: true,
		matchBrackets: true,
		mode: "application/x-httpd-php",
		indentUnit: 4,
		indentWithTabs: true,
		enterMode: "keep",
		tabMode: "shift",
		extraKeys: {"Ctrl-Space": function(cm) {CodeMirror.simpleHint(cm, CodeMirror.javascriptHint);}}
	});

	$('.CodeMirror').addClass('ui-widget ui-widget-content ui-corner-all');
	$('.CodeMirror').css('font-size', '13px');
	$('.CodeMirror').css('font-family', 'Courier New');

	foriaAutoNewsResize();


	$("button").button();

	$( "#editorSizeShort" ).click(function() {
		editorResize();
		return false;
	});

	$( "#editorSizeFull" ).click(function() {
		editorResize();
		return false;
	});

});

function editorResize() {
	$( "#editorSizeShort" ).button( "option", "label", stateOfEditor['short']==true?'Развернуть':'Свернуть' );
	$( "#editorSizeFull" ).button( "option", "label", stateOfEditor['short']==false?'Развернуть':'Свернуть' );
	stateOfEditor['short']=!stateOfEditor['short'];
	stateOfEditor['full']!=stateOfEditor['short'];
	foriaAutoNewsResize();
}

var stateOfEditor = {
	'short':true,
	'full':false,
};

function foriaAutoNewsResize()
{
	var baseOffsetHeight = 190;
	var needHeight = $(window).height() - baseOffsetHeight;
	var sHeight = 10;
	var fHeight = 10;
	if (stateOfEditor['short']==true) {
		sHeight = needHeight - 10;
	} else {
		fHeight = needHeight - 10
	}

	$('.CodeMirror-scroll').css('height', needHeight - 10);
	$.each($('.CodeMirror-scroll'), function(index, value) {
		if (index == 0)
  			$(value).css('height', sHeight);
		if (index == 1)
  			$(value).css('height', fHeight);
	});

	//console.log($('.CodeMirror-scroll').next());
}

$(window).resize(function() {
	foriaAutoNewsResize();
});

</script>

<?php if (!empty($error)) { ?>
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
	<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
	<strong>Внимание:</strong> <?php echo $error; ?></p>
</div>
<?php } ?>

<input type="hidden" name="act" value="new">

<?php if (isset($request['id'])) { ?>
<input type="hidden" name="id" value="<?php echo $request['id']; ?>">
<?php } ?>

<label>Название</label><br>
<input type="text" maxlenght="200px" name="title" style="width:100%;" value="<?php
if (isset($request['title']))
{
	echo(htmlentities($request['title'], ENT_COMPAT, 'UTF-8'));
}
?>"><br>

<label style="margin-right:5px;">Канал</label>
	<select style="width:200px; margin-right:10px" name="channel">
		<option value="">Все каналы
		<?php
foreach ($channels as $ch)
{
	$request['channel'] == $ch?$selected=' selected':$selected='';
	print '<option value="'.htmlentities($ch, ENT_COMPAT, 'UTF-8').'"'.$selected.'>'.htmlentities($ch, ENT_COMPAT, 'UTF-8');
}

		?></select>

<label style="margin-right:5px;">Дата публикации</label>
<input type="text" maxlenght="200" name="date" style="width:200px" value="<?php
if (isset($request['date']) && !empty($request['date']))
{
	echo(htmlentities($request['date'], ENT_COMPAT, 'UTF-8'));
} else {
	echo date ('Y-m-d H:i', time());
}
?>">

<label style="margin-left:10px; width:auto">Активная</label><input type="checkbox" name="active" value="on" <?php
if (isset($request['active']) && ($request['active'] == 'on' || $request['active'] == 'true') )
{
	echo "checked";
}
?>><br>
<label>Кратко</label>
<button id="editorSizeShort" style="float:right">Свернуть</button>
<br><textarea name="short" id="txtShort"><?php
if (isset($request['short']))
{
	echo(htmlentities($request['short'], ENT_COMPAT, 'UTF-8'));
}
?></textarea><br>
<label>Полно</label>
<button id="editorSizeFull" style="float:right">Развернуть</button>
<br><textarea name="full" id="txtFull"><?php
if (isset($request['full']))
{
	echo(htmlentities($request['full'], ENT_COMPAT, 'UTF-8'));
}
?></textarea>
<button name="cmd" value="create_news" id="btnNewsCreateNew">
<?php if (isset($request['id'])) { ?>
Сохранить новость
<?php } else { ?>
Создать новость
<?php } ?>
	</button>
<a id="btnNewsBack" href="<?php echo base_url("admin/tools/exec_tools/News");?>">Нет спасибо, в другой раз</a>